package logs

import (
	"fmt"
	"log"
)

type Write struct {
	bs []byte
}

func (this *Write) Write(p []byte) (n int, err error) {
	this.bs = append(this.bs, p...)
	return len(p), nil
}

func (this *Write) String() string {
	return string(this.Bytes())
}

func (this *Write) Bytes() []byte {
	return this.bs
}

func newWrite(prefix string, flag, level int, tag []string, s ...interface{}) *Write {
	w := &Write{}
	content := fmt.Sprint(s...)
	tags := ""
	for _, v := range tag {
		tags += fmt.Sprintf("[%s]", v)
	}
	if len(tags) > 0 {
		content = tags + " " + content
	}
	_ = log.New(w, prefix, flag).Output(level, content)
	return w
}
